package com.zzl.alligator.management.system.controller;

import com.zzl.alligator.common.util.ExcelUtils;
import com.zzl.alligator.framework.base.controller.BaseController;
import com.zzl.alligator.framework.support.web.vo.JsonResult;
import com.zzl.alligator.management.system.domain.SysOperLog;
import com.zzl.alligator.management.system.service.ISysOperLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 操作日志记录(SysOperLog)控制层
 *
 * @author zhouziliang
 * @since 2020-07-06
 */
@RestController
@RequestMapping("/system/operlog")
public class SysOperLogController extends BaseController {
    
    /**
     * 服务对象
     */
    @Autowired
    private ISysOperLogService sysOperLogService;

    /**
     * 分页查询所有数据
     *
     * @param sysOperLog 查询实体
     * @return 所有数据
     */
    @GetMapping
    public JsonResult findList(SysOperLog sysOperLog) {
        startPage();
        List<SysOperLog> sysOperLogList = sysOperLogService.findSysOperLogList(sysOperLog);
        return JsonResult.success(getDataTable(sysOperLogList));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param operId 主键
     * @return 单条数据
     */
    @GetMapping("/{operId}")
    public JsonResult findById(@PathVariable Long operId) {
        return JsonResult.success(sysOperLogService.findSysOperLogById(operId));
    }

    /**
     * 新增数据
     *
     * @param sysOperLog 实体对象
     * @return 新增结果
     */
    @PostMapping
    public JsonResult add(@RequestBody SysOperLog sysOperLog) {
        return toAjax(this.sysOperLogService.insertSysOperLog(sysOperLog));
    }

    /**
     * 修改数据
     *
     * @param sysOperLog 实体对象
     * @return 修改结果
     */
    @PutMapping
    public JsonResult update(@RequestBody SysOperLog sysOperLog) {
        return toAjax(this.sysOperLogService.updateSysOperLog(sysOperLog));
    }

    /**
     * 删除数据
     *
     * @param operId 主键
     * @return 删除结果
     */
    @DeleteMapping("/{operId}")
    public JsonResult delete(@PathVariable Long operId) {
        return toAjax(this.sysOperLogService.deleteById(operId));
    }

    /**
     * 清空数据
     *
     * @return 删除结果
     */
    @DeleteMapping("/clean")
    public JsonResult clean() {
        return JsonResult.success(this.sysOperLogService.clean());
    }


    /**
     * 导出数据
     * 
     * @param sysOperLog 条件
     * @return 导出文件路径
     */
    @GetMapping("/export")
    public JsonResult export(SysOperLog sysOperLog) {
        List<SysOperLog> list = sysOperLogService.findSysOperLogList(sysOperLog);
        ExcelUtils<SysOperLog> util = new ExcelUtils<>(SysOperLog.class);
        return util.exportExcel(list, "操作日志记录数据");
    }
}